package com.zut.controller.category;

import com.alibaba.fastjson.JSON;
import com.zut.pojo.Category;
import com.zut.service.CategoryService;
import com.zut.service.impl.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;

/**
 * @author 张晨
 * @date 2024/9/12 10:28
 * @desc
 */
@WebServlet("/category/select")
public class CategorySelectController extends HttpServlet {
    private CategoryService categoryService = new CategoryServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

       List<Category> list =  categoryService.selectAll();

       String jsonString = JSON.toJSONString(list);

       resp.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
